<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:redirect="http://xml.apache.org/xalan/redirect" 
extension-element-prefixes="redirect"
version="2.0">

<xsl:output method="text" indent="yes" name="java"/>
<xsl:template match="/datastores">

<xsl:variable name="DATA_FW_PACKAGE" select="@datafwpackage"/>
<xsl:variable name="POJO_PACKAGE" select="@pojopackage"/>
<xsl:variable name="DAO_PACKAGE" select="@daopackage"/>
<xsl:variable name="COMMON_PACKAGE" select="@commonpackage"/>
<xsl:variable name="JS_PACKAGE" select="@jspackage"/>
<xsl:variable name="POJO_FILEPATH" select="@pojofilepath"/>
<xsl:variable name="DAO_FILEPATH" select="@daofilepath"/>
<xsl:variable name="JS_FILEPATH" select="@jsfilepath"/>
<xsl:variable name="COMMON_FILEPATH" select="@commonfilepath"/>

<xsl:for-each select="./datastore">
starting the toolrunner
	 
#### starting the tool runner for POJO
		<xsl:for-each select="./bean">
			<xsl:call-template name="processPojo">
				<xsl:with-param name="DATA_FW_PACKAGE" select="$DATA_FW_PACKAGE"/>
				<xsl:with-param name="PACKAGE" select="$POJO_PACKAGE"/> 
				<xsl:with-param name="FILEPATH" select="$POJO_FILEPATH"/>
			</xsl:call-template>
		</xsl:for-each>
		
#### completed the tool runner for POJO ####
	
#### starting the tool runner for DAO
		<xsl:for-each select="./bean">
			<xsl:call-template name="processDAO">
				<xsl:with-param name="DATA_FW_PACKAGE" select="$DATA_FW_PACKAGE"/>
				<xsl:with-param name="PACKAGE" select="$DAO_PACKAGE"/> 
				<xsl:with-param name="POJO_PACKAGE" select="$POJO_PACKAGE"/>
				<xsl:with-param name="FILEPATH" select="$DAO_FILEPATH"/>
			</xsl:call-template>
		</xsl:for-each>
		
#### completed the tool runner for DAO ####
	
	
#### starting the tool runner for DAOFinder
			<xsl:call-template name="processDAOFinder">
				<xsl:with-param name="DATA_FW_PACKAGE" select="$DATA_FW_PACKAGE"/>
				<xsl:with-param name="PACKAGE" select="$COMMON_PACKAGE"/> 
				<xsl:with-param name="POJO_PACKAGE" select="$POJO_PACKAGE"/>
				<xsl:with-param name="DAO_PACKAGE" select="$DAO_PACKAGE"/> 
				<xsl:with-param name="FILEPATH" select="$COMMON_FILEPATH"/>
			</xsl:call-template>
		
#### completed the tool runner for DAOFinder ####
	
	
#### starting the tool runner for Initer
			<xsl:call-template name="processInitor">
				<xsl:with-param name="DATA_FW_PACKAGE" select="$DATA_FW_PACKAGE"/>
				<xsl:with-param name="PACKAGE" select="$COMMON_PACKAGE"/> 
				<xsl:with-param name="POJO_PACKAGE" select="$POJO_PACKAGE"/>
				<xsl:with-param name="FILEPATH" select="$COMMON_FILEPATH"/>
			</xsl:call-template>
		
#### completed the tool runner for Initer ####
	
	
#### starting the tool runner for JS
		<xsl:for-each select="./beans/bean">
			<xsl:call-template name="processJSDAO">
				<xsl:with-param name="PACKAGE" select="$JS_PACKAGE"/>
				<xsl:with-param name="FILEPATH" select="$JS_FILEPATH"/>
			</xsl:call-template>
		</xsl:for-each>
		
#### completed the tool runner for JS ####
</xsl:for-each>
completd the toolrunner
</xsl:template>

<xsl:template name="processPojo">
	<xsl:param name="DATA_FW_PACKAGE"/>
	<xsl:param name="PACKAGE"/>
	<xsl:param name="FILEPATH"/>
<xsl:variable name="filename" select="concat($FILEPATH, @name,'.java')" />
creating <xsl:value-of select="$filename" />
<redirect:write file="{$filename}" >/**********************************************/
/** THIS FILE IS AUTO GENERATED. DO NOT EDIT **/
/**********************************************/
package <xsl:value-of select="$PACKAGE"/>;
<xsl:variable name="JAVAUTILPACKAGENEEDED"><xsl:call-template name="checkUtilPackage"></xsl:call-template></xsl:variable>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
<xsl:if test="$JAVAUTILPACKAGENEEDED = 'true'">import java.util.*;</xsl:if>
<xsl:if test="string(@transport) = 'true'">import <xsl:value-of select="$DATA_FW_PACKAGE"/>.model.Pojo;</xsl:if>

public class <xsl:value-of select="@name"/><xsl:if test="@extends != ''"> extends <xsl:value-of select="@extends"/></xsl:if> implements Pojo
{
	public static Logger logger = LoggerFactory.getLogger(<xsl:value-of select="@name"/>.class);
<xsl:for-each select="./parameters/param">
	<xsl:call-template name="declarevariable">
	</xsl:call-template>
</xsl:for-each>
	public <xsl:value-of select="@name"/>()
	{
	}
<xsl:for-each select="./parameters/param">
	<xsl:call-template name="createGetterSetter">
	</xsl:call-template>
</xsl:for-each>
}
</redirect:write>
</xsl:template>

<xsl:template name="processDAO">
	<xsl:param name="DATA_FW_PACKAGE"/>
	<xsl:param name="PACKAGE"/>
	<xsl:param name="POJO_PACKAGE"/>
	<xsl:param name="FILEPATH"/>
	
<xsl:variable name="filename" select="concat($FILEPATH, @name,'DAO.java')" />
creating <xsl:value-of select="$filename" />
<redirect:write file="{$filename}">

<xsl:variable name="NUMQUERIES" select="count(./queries/query)"/>	
<xsl:variable name="CLASSNAME" select="@name"/>/**********************************************/
/** THIS FILE IS AUTO GENERATED. DO NOT EDIT **/
/**********************************************/
package <xsl:value-of select="$PACKAGE"/>;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.DataException;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.DataBaseException;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.QueryExecutor;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.DataBaseConnection;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.model.DataAccessor;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.model.Parameter;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.model.Query;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.model.DataBaseField;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.model.Field;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.model.Pojo;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.utils.ReflectionUtil;
import <xsl:value-of select="$POJO_PACKAGE"/>.<xsl:value-of select="$CLASSNAME"/>;

public class <xsl:value-of select="@name"/>DAO implements DataAccessor {
	public static Logger logger = LoggerFactory.getLogger(<xsl:value-of select="@name"/>DAO.class);
	private static DataBaseField[] fields;
	private static Query[] queries;
	private static Map&lt;String, Method&gt; serviceMethods;
	<xsl:for-each select="./parameters/param">
		<xsl:call-template name="declareFieldIds"></xsl:call-template>
	</xsl:for-each>
	
	public static final int _QUERY_INSERT_ = 0;
	public static final int _QUERY_UPDATE_ = 1;
	public static final int _QUERY_DELETE_ = 2;
	public static final int _QUERY_LOAD_ = 3;<xsl:for-each select="./queries/query">
	public static final int QUERY_<xsl:value-of select="translate(name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> = <xsl:value-of select="position() + 3"/>;
	</xsl:for-each>
	static {
		queries = new Query[<xsl:value-of select="count(./queries/query) + 4"/>];
		queries[_QUERY_INSERT_] = new Query("insert into <xsl:value-of select="@tablename"/>(<xsl:call-template name="createInsertParams"/>) values (<xsl:call-template name="createInsertParamsInputs"/>)", false, false);
		queries[_QUERY_UPDATE_] = new Query("update <xsl:value-of select="@tablename"/> set <xsl:call-template name="createUpdateParams"/> where <xsl:call-template name="createLoadParams"/>", false, false);
		queries[_QUERY_DELETE_] = new Query("delete from <xsl:value-of select="@tablename"/> where <xsl:call-template name="createLoadParams"/>", false, false);
		queries[_QUERY_LOAD_] = new Query("select <xsl:call-template name="createInsertParams"/> from admin where <xsl:call-template name="createLoadParams"/>", false, false);<xsl:for-each select="./queries/query"><xsl:call-template name="createQuery"></xsl:call-template></xsl:for-each>
		serviceMethods = new HashMap&lt;String, Method&gt;();

		try {
			HashMap&lt;String, Field&gt; dbFields = ReflectionUtil.getFieldsAsHashMap(<xsl:value-of select="$CLASSNAME"/>.class, DataBaseField.class);
			fields = new DataBaseField[dbFields.size()];<xsl:for-each select="./parameters/param"><xsl:call-template name="createField"></xsl:call-template></xsl:for-each>
			initServices();
		} catch (DataException se) {
			logger.error("Error in getting Database Feilds", se);
		}
	}
	<xsl:variable name="POJO_TYPE" select="@name" />

	public Pojo create(DataBaseConnection cxn, Pojo object) throws DataBaseException {
		Parameter[] inputParams = new Parameter[<xsl:value-of select="count(./parameters/param[not(@primarykey)])"/>];
		<xsl:for-each select="./parameters/param[not(@primarykey)]">
			<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, "<xsl:value-of select="@name"/>", ((<xsl:value-of select="$POJO_TYPE"/>)object).get<xsl:value-of select="$NAME"/>());
		</xsl:for-each>
		DataBaseField[] loadFields = { <xsl:for-each select="./parameters/param[@primarykey = 'true']"><xsl:if test="position() != 1">, </xsl:if>fields[FIELD_<xsl:value-of select="translate(@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>]</xsl:for-each> };
		QueryExecutor qe = new QueryExecutor();
		queries[_QUERY_INSERT_].setGetGeneratedKeys(true);
		qe.doCreateOneRow(cxn, queries[_QUERY_INSERT_], inputParams, loadFields, (<xsl:value-of select="@name"/>)object);
		return object;
	}
	
	public Pojo update(DataBaseConnection cxn, Pojo object) throws DataBaseException {
		<xsl:variable name="NUM_NON_PRIMARY_FIELDS" select="count(./parameters/param[not(@primarykey)])"/>
		<xsl:variable name="NUM_PRIMARY_FIELDS" select="count(./parameters/param[@primarykey = 'true'])"/>
		Parameter[] inputParams = new Parameter[<xsl:value-of select="$NUM_NON_PRIMARY_FIELDS + $NUM_PRIMARY_FIELDS"/>];
		<xsl:for-each select="./parameters/param[not(@primarykey)]">
			<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, "<xsl:value-of select="@name"/>", ((<xsl:value-of select="$POJO_TYPE"/>)object).get<xsl:value-of select="$NAME"/>());
		</xsl:for-each>
		
		<xsl:for-each select="./parameters/param[@primarykey = 'true']">
			<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="$NUM_NON_PRIMARY_FIELDS + position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, "<xsl:value-of select="@name"/>", ((<xsl:value-of select="$POJO_TYPE"/>)object).get<xsl:value-of select="$NAME"/>());
		</xsl:for-each>	
			
		DataBaseField[] loadFields = {};
		QueryExecutor qe = new QueryExecutor();
		qe.doCreateOneRow(cxn, queries[_QUERY_UPDATE_], inputParams, loadFields, object);
		return object;
	}
	
	public Pojo delete(DataBaseConnection cxn, Pojo object) throws DataBaseException {
		Parameter[] inputParams = new Parameter[<xsl:value-of select="count(./parameters/param[@primarykey = 'true'])"/>];
		<xsl:for-each select="./parameters/param[@primarykey = 'true']">
			<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, "<xsl:value-of select="@name"/>", ((<xsl:value-of select="$POJO_TYPE"/>)object).get<xsl:value-of select="$NAME"/>());
		</xsl:for-each>			
		DataBaseField[] loadFields = {};	
		QueryExecutor qe = new QueryExecutor();
		qe.doCreateOneRow(cxn, queries[_QUERY_DELETE_], inputParams, loadFields, object);
		return object;
	}
	
	public Pojo load(DataBaseConnection cxn, Pojo object) throws DataBaseException {
		Parameter[] inputParams = new Parameter[<xsl:value-of select="count(./parameters/param[@primarykey = 'true'])"/>];
		<xsl:for-each select="./parameters/param[@primarykey = 'true']">
			<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, "<xsl:value-of select="@name"/>", ((<xsl:value-of select="$POJO_TYPE"/>)object).get<xsl:value-of select="$NAME"/>());
		</xsl:for-each>
		DataBaseField[] loadFields = { <xsl:for-each select="./parameters/param[not(@primarykey)]"><xsl:if test="position() != 1">, </xsl:if>fields[FIELD_<xsl:value-of select="translate(@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>]</xsl:for-each> };
		QueryExecutor qe = new QueryExecutor();
		return cast(qe.doLoadRows(cxn, queries[_QUERY_LOAD_], inputParams, loadFields, null, null, true));
	}
	<xsl:for-each select="./queries/query">
		<xsl:call-template name="createQueryFunction">
			<xsl:with-param name="QUERYID" select="translate(name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:with-param name="CLASSNAME" select="$CLASSNAME"/>
		</xsl:call-template>
	</xsl:for-each>

	public <xsl:value-of select="@name"/>[] castToArray(Object object) {
		Object[] obejctArr = (Object[]) object;
		<xsl:value-of select="@name"/>[] toRet = new <xsl:value-of select="@name"/>[obejctArr.length];
		for (int i = 0; i &lt; obejctArr.length; i++) {
			toRet[i] = cast(obejctArr[i]);
		}
		return toRet;
	}

	public <xsl:value-of select="@name"/> cast(Object object) {
		return (<xsl:value-of select="@name"/>.class).cast(object);
	}
	
	private static void initServices() throws DataBaseException {
		try
		{
			serviceMethods = ReflectionUtil.getMethodsMap(<xsl:value-of select="@name"/>DAO.class);
		}
		catch (Exception e) {
			throw new DataBaseException("Error in initing Service Methods");
		}
	}
	
	public Method getServiceMethod(String operation) throws DataBaseException {
		return serviceMethods.get(operation);
	}
}
</redirect:write>
</xsl:template>


<xsl:template name="processDAOFinder">
	<xsl:param name="DATA_FW_PACKAGE"/>
	<xsl:param name="PACKAGE"/>
	<xsl:param name="POJO_PACKAGE"/>
	<xsl:param name="DAO_PACKAGE"/>
	<xsl:param name="FILEPATH"/>
<xsl:variable name="filename" select="concat($FILEPATH, 'DAOFinder.java')" />
creating DAOFinder.java
<redirect:write file="{$filename}" >/**********************************************/
/** THIS FILE IS AUTO GENERATED. DO NOT EDIT **/
/**********************************************/
package <xsl:value-of select="$PACKAGE"/>;

import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.DataBaseException;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.database.model.DataAccessor;
import <xsl:value-of select="$DAO_PACKAGE"/>.*;
import java.util.HashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DAOFinder
{
	Logger logger = LoggerFactory.getLogger(getClass());
	HashMap&lt;String, DataAccessor&gt; daoMappings = null;
 
	public DAOFinder()
	{
		daoMappings = new HashMap&lt;String, DataAccessor&gt;();
		try
		{
			loadAll();
		} catch (Throwable t) {
			logger.error("Unalbe to load the dao classes", t);
		}
	}
	
	public void loadAll() throws DataBaseException
	{
		try {
			<xsl:for-each select="./bean">daoMappings.put("<xsl:value-of select="@name"/>", new <xsl:value-of select="@name"/>DAO());</xsl:for-each>
		} catch (Throwable t) {
			throw new DataBaseException(t);
		}		
	}
	
	public DataAccessor findDAO(String pojoName)
	{
		return  daoMappings.get(pojoName);
	}
}
</redirect:write>
</xsl:template>

<xsl:template name="processInitor">
	<xsl:param name="DATA_FW_PACKAGE"/>
	<xsl:param name="PACKAGE"/>
	<xsl:param name="POJO_PACKAGE"/>
	<xsl:param name="FILEPATH"/>
<xsl:variable name="filename" select="concat($FILEPATH, 'MediaInitializer.java')" />
creating Initor.java
<redirect:write file="{$filename}" >/**********************************************/
/** THIS FILE IS AUTO GENERATED. DO NOT EDIT **/
/**********************************************/
package <xsl:value-of select="$PACKAGE"/>;

import <xsl:value-of select="$POJO_PACKAGE"/>.*;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.model.DataRegistrar;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.DataException;
import <xsl:value-of select="$DATA_FW_PACKAGE"/>.transport.Transporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MediaInitializer extends DataRegistrar
{
	Logger logger = LoggerFactory.getLogger(getClass());
	
	public void init()
	{
		super.init();
		initTransportable();
	}
	
	public void initTransportable()
	{
		try
		{
			<xsl:for-each select="./bean[@transport='true']">Transporter.registerClass((new <xsl:value-of select="@name"/>()).getClass(), "<xsl:value-of select="@name"/>");</xsl:for-each>
		}
		catch(DataException de)
		{
			logger.error("Error in initTransportable", de);
		}
	
	}
}
</redirect:write>
</xsl:template>


<xsl:template name="processJSDAO">
	<xsl:param name="PACKAGE"/>
	<xsl:param name="FILEPATH"/>
</xsl:template>

<xsl:template name="getvariabletype">
	<xsl:param name="SQLTYPE"/>
	<xsl:param name="JAVATYPE"/>	
	<xsl:choose>
		<xsl:when test="string($SQLTYPE) != ''"><!-- creating a string obj will take care of null case as well as empty string case-->
			<xsl:if test="$SQLTYPE = 'BIT'">boolean</xsl:if>
			<xsl:if test="$SQLTYPE = 'TINYINT'">boolean</xsl:if>
			<xsl:if test="$SQLTYPE = 'SMALLINT'">int</xsl:if>
			<xsl:if test="$SQLTYPE = 'INTEGER'">int</xsl:if>
			<xsl:if test="$SQLTYPE = 'BIGINT'">long</xsl:if>
			<xsl:if test="$SQLTYPE = 'FLOAT'">float</xsl:if>
			<xsl:if test="$SQLTYPE = 'DOUBLE'">double</xsl:if>
			<xsl:if test="$SQLTYPE = 'DECIMAL'">double</xsl:if>
			<xsl:if test="$SQLTYPE = 'DATE'">long</xsl:if>
			<xsl:if test="$SQLTYPE = 'TIMESTAMP'">long</xsl:if>
			<xsl:if test="$SQLTYPE = 'VARCHAR'">String</xsl:if>    
		</xsl:when>
		<xsl:otherwise><xsl:value-of select="$JAVATYPE"/></xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="declarevariable">
	<xsl:variable name="JAVATYPE">
		<xsl:call-template name="getvariabletype">
			<xsl:with-param name="SQLTYPE" select="@sqltype"/>
			<xsl:with-param name="JAVATYPE" select="@javatype"/>
		</xsl:call-template>
	</xsl:variable>	private<xsl:text> </xsl:text><xsl:value-of select="$JAVATYPE"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>;
</xsl:template>

<xsl:template name="createGetterSetter">
	<xsl:variable name="JAVATYPE">
		<xsl:call-template name="getvariabletype">
			<xsl:with-param name="SQLTYPE" select="@sqltype"/>
			<xsl:with-param name="JAVATYPE" select="@javatype"/>			
		</xsl:call-template>
	</xsl:variable>

	<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
	<xsl:variable name="NAME"><xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>
	public <xsl:value-of select="$JAVATYPE"/> get<xsl:value-of select="$NAME"/>()
	{
		return this.<xsl:value-of select="@name"/>;
	}
	
	public void set<xsl:value-of select="$NAME"/>(<xsl:value-of select="$JAVATYPE"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>)
	{
		this.<xsl:value-of select="@name"/> = <xsl:value-of select="@name"/>;
	} 
</xsl:template>

<xsl:template name="declareFieldIds">
	public static final int FIELD_<xsl:value-of select="translate(@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> = <xsl:value-of select="position() - 1"/>;</xsl:template>

<xsl:template name="createQuery">
		queries[QUERY_<xsl:value-of select="translate(name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>] = new Query("<xsl:value-of select="sql"/>", <xsl:value-of select="isScrollSensitive"/>, <xsl:value-of select="isUpdateable"/>);</xsl:template>

<xsl:template name="createField">
			fields[FIELD_<xsl:value-of select="translate(@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>] = (DataBaseField) dbFields.get("<xsl:value-of select="@name"/>");</xsl:template>

<xsl:template name="createQueryFunction">
	<xsl:param name="QUERYID"/>
	<xsl:param name="CLASSNAME"/>
	<xsl:variable name="NUMPARAMS" select="count(./inputs/parameter)"/>
	<xsl:variable name="NUMMEMBERPARAMSHAVESETFALSE" select="count(./inputs/member[@set='false'])"/>
	<xsl:variable name="NUMMEMBERPARAMS" select="count(./inputs/member)"/>
	<xsl:variable name="NUMOUTPUTMEMBERPARAMS" select="count(./output/member)"/>
	public <xsl:choose><xsl:when test="@type = 'bulkload'"><xsl:value-of select="$CLASSNAME"/>[]</xsl:when>
		<xsl:when test="@type = 'load'"><xsl:value-of select="$CLASSNAME"/></xsl:when>
    		<xsl:otherwise>void</xsl:otherwise></xsl:choose><xsl:text> </xsl:text>
		<xsl:value-of select="name"/>(DataBaseConnection cxn<xsl:if test="@type = 'create' or @type = 'update' or @type = 'delete' or $NUMMEMBERPARAMSHAVESETFALSE &gt; 0">, <xsl:value-of select="$CLASSNAME"/> object</xsl:if><xsl:for-each select="./inputs/member"><xsl:if test="@set = 'true'">
				<xsl:variable name="PARAMNAME" select="@name"/>
				<xsl:variable name="PARAM"><xsl:call-template name="getparamjavatype"><xsl:with-param name="PARAMNAME" select="$PARAMNAME"/></xsl:call-template></xsl:variable>
				<xsl:text>, </xsl:text><xsl:value-of select="$PARAM"/><xsl:text> </xsl:text><xsl:value-of select="$PARAMNAME"/>
			</xsl:if></xsl:for-each><xsl:for-each select="./inputs/parameter">
				<xsl:variable name="PARAMNAME" select="@name"/>
				<xsl:variable name="PARAM"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>
				<xsl:text>, </xsl:text><xsl:value-of select="$PARAM"/><xsl:text> </xsl:text><xsl:value-of select="$PARAMNAME"/>
			</xsl:for-each>) throws DataBaseException {
		Parameter[] inputParams = new Parameter[<xsl:value-of select="$NUMPARAMS + $NUMMEMBERPARAMS"/>];
		<xsl:for-each select="./inputs/member">
			<xsl:variable name="PARAMNAME" select="@name"/>
			<xsl:variable name="PARAM"><xsl:call-template name="getparamjavatype"><xsl:with-param name="PARAMNAME" select="$PARAMNAME"/></xsl:call-template></xsl:variable>
			<xsl:variable name="NAMECHAR1" select="translate(substring(@name, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
			<xsl:variable name="NAME">
			<xsl:value-of select="$NAMECHAR1"/><xsl:value-of select="substring(@name, 2)"/></xsl:variable>inputParams[<xsl:value-of select="position()-1"/>] = new Parameter(<xsl:value-of select="$PARAM"/>.class, <xsl:if test="@set = 'true'">"<xsl:value-of select="@name"/>", <xsl:value-of select="@name"/></xsl:if><xsl:if test="@set != 'true'">"<xsl:value-of select="@name"/>", object.get<xsl:value-of select="$NAME"/>()</xsl:if>);
		</xsl:for-each>
		<xsl:for-each select="./inputs/parameter">
			<xsl:variable name="PARAMNAME" select="@name"/>
			<xsl:variable name="PARAMTTYPE"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:variable>inputParams[<xsl:value-of select="$NUMMEMBERPARAMS + (position()-1)"/>] = new Parameter(<xsl:value-of select="$PARAMTTYPE"/>.class, "<xsl:value-of select="$PARAMNAME"/>", <xsl:value-of select="$PARAMNAME"/>);
		</xsl:for-each>
		DataBaseField[] loadFields = { <xsl:for-each select="./outputs/member"><xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>fields[FIELD_<xsl:value-of select="translate(@name, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>]</xsl:for-each> };
		QueryExecutor qe = new QueryExecutor();
		<xsl:if test="@type = 'load' or @type = 'bulkload'">return<xsl:if test="@type = 'load'"> cast(</xsl:if><xsl:if test="@type = 'bulkload'"> castToArray(</xsl:if></xsl:if>qe.<xsl:choose>
			<xsl:when test="@type = 'create'">doCreateOneRow</xsl:when>
			<xsl:when test="@type = 'update' or @type = 'bulkupdate'">doUpdate</xsl:when>
			<xsl:when test="@type = 'delete' or @type = 'bulkdelete'">doDelete</xsl:when>
			<xsl:when test="@type = 'load' or @type = 'bulkload'">doLoadRows</xsl:when></xsl:choose>(cxn, queries[QUERY_<xsl:value-of select="$QUERYID"/>], inputParams, loadFields,<xsl:choose><xsl:when test="@type = 'create' or @type = 'update' or @type = 'delete' or $NUMMEMBERPARAMSHAVESETFALSE &gt; 0"> object</xsl:when><xsl:otherwise> null</xsl:otherwise></xsl:choose><xsl:choose>
				<xsl:when test="@type = 'update' or @type = 'delete'">, false</xsl:when>
				<xsl:when test="@type = 'bulkupdate' or @type = 'bulkdelete'">, true</xsl:when>				
				<xsl:when test="@type = 'load'">, null, true</xsl:when>
				<xsl:when test="@type = 'bulkload'">, <xsl:value-of select="$CLASSNAME"/>.class, false</xsl:when>
			</xsl:choose><xsl:if test="@type = 'load' or @type = 'bulkload'">)</xsl:if>);
	}
</xsl:template>

<xsl:template name="createQueryParameter">
	<xsl:call-template name="getvariabletype">
		<xsl:with-param name="SQLTYPE" select="@sqltype"/>
		<xsl:with-param name="JAVATYPE" select="@javatype"/>			
	</xsl:call-template>
</xsl:template>

<xsl:template name="getparamjavatype">
    <xsl:param name="PARAMNAME"/>
<xsl:for-each select="../../../../parameters/param"><xsl:if test="@name = $PARAMNAME"><xsl:call-template name="getvariabletype"><xsl:with-param name="SQLTYPE" select="@sqltype"/><xsl:with-param name="JAVATYPE" select="@javatype"/></xsl:call-template></xsl:if></xsl:for-each>       
</xsl:template>

<xsl:template name="checkUtilPackage">
<xsl:variable name="NUMHASHMAP" select="count(./parameters/param[@javatype = 'HashMap&lt;String, String&gt;'])"/>
<xsl:variable name="NUMTREEMAP" select="count(./parameters/param[@javatype = 'TreeMap&lt;String, String&gt;'])"/><xsl:if test="$NUMHASHMAP + $NUMTREEMAP &gt; 0">true</xsl:if>
</xsl:template>

<xsl:template name="createInsertParamsInputs">
	<xsl:for-each select="./parameters/param[not(@primarykey)]">
		<xsl:if test="position() != 1">, </xsl:if>?</xsl:for-each>
</xsl:template>



<xsl:template name="createInsertParams">
	<xsl:for-each select="./parameters/param[not(@primarykey)]">
		<xsl:if test="position() != 1">, </xsl:if>
		<xsl:value-of select="@name"></xsl:value-of>
	</xsl:for-each>
</xsl:template>

<xsl:template name="createUpdateParams">
<xsl:for-each select="./parameters/param[not(@primarykey)]"><xsl:if test="position() != 1">, </xsl:if><xsl:value-of select="@name"></xsl:value-of>=?</xsl:for-each></xsl:template>

<xsl:template name="createLoadParams">
	<xsl:for-each select="./parameters/param[@primarykey = 'true']">
		<xsl:if test="position() != 1">, </xsl:if>
		<xsl:value-of select="@name"></xsl:value-of>=?</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
